<template>
    <div class="goods-detail" v-if="goodsDetailMsg && Object.keys(goodsDetailMsg).length > 0">
        <slide-bottom @closeSlideBottom="closeSlideBottom" ref="slideBottom">
            <div class="goods-detail-box user-touch">
                <div>
                <h4 class="goods-detail-title">
                    {{goodsDetailMsg.title}}
                    <img class="icon-close" @click="closeSlideBottom" src="../../../../assets/images/cart/slide_down.png" alt="">
                </h4>
                <div class="goods-detail-price">
                    <span class="fontSize12">{{goodsDetailMsg.currency}}</span>{{goodsDetailMsg.price}}
                </div>
                <div class="goods-detail-des">
                    {{goodsDetailMsg.description}}
                </div>
                <div v-if="Array.isArray(goodsDetailMsg.imgList) && goodsDetailMsg.imgList.length > 0">
                    <img class="width-height-full positionR displayBlock" v-for="(value,index) in goodsDetailMsg.imgList" :src="value">
                </div>
<!--                <swiper :swiperContentProp="{imgList:goodsDetailMsg.imgList}"></swiper>-->
                </div>
                <!--TODO 买家秀等各个模块 暂时没有先为false-->
                <div v-if="goodsDetailMsg.modlueList && goodsDetailMsg.modlueList.length > 0 && false">
                    <goods-boxs v-for="(value,key) in goodsDetailMsg.modlueList" :goodsDetailProps="value" :key="key"></goods-boxs>
                </div>
                <div class="displayFlex flexCenter detail-btns">
                    <button @click="addToCart(goodsDetailMsg.itemId)" class="detail-btn buy-btn">加入购物车</button>
                    <button @click="buyNow(goodsDetailMsg.itemId)" class="detail-btn add-btn">立即购买</button>
                </div>
                <!--TODO 这里还没有跳转-->
                <!--@click="addToCart(goodsDetailMsg.itemId)"-->
                <router-link class="right-slide-icon" to="/order/cart">
                    <img class="width-height-full" @click="" src="../../../../assets/images/cart/buy_icon.png" alt="">
                    <span class="cart-number" v-if="cartGoodsLength">{{cartGoodsLength}}</span>
                </router-link>
            </div>
        </slide-bottom>
    </div>
</template>

<script>
    import GoodsBox from '../../../../components/commonComponents/boxItem/GoodsBox';
    import {mapState} from 'vuex'
    export default {
        name: "GoodsDetail",
        props:{
            goodsDetailProps:Object
        },
        data(){
            return{
                goodsDetailMsg:{
                    // storeId:0,//店铺id
                    // itemId:0,//商品id
                    // title:'',//商品标题
                    // currency:'',//商品价格符号
                    // price:'',//商品价格
                    // imgList:[],//商品详情轮播图的图片，
                    // description:'',
                    // modlueList:[
                    //     {
                    //         title:'买家秀',
                    //         list:[]
                    //     }
                    // ]
                },
            }
        },
        mounted(){
            this.goodsDetailMsg = Object.assign({},this.goodsDetailMsg,this.goodsDetailProps);
        },
        computed:{
            ...mapState({
                cartGoodsLength:state=>state.api.cartObj.cartGoodsLength,
            }),
        },
        methods:{
            closeSlideBottom(boolean=false){
                this.$refs.slideBottom.showSlide = false;
                setTimeout(()=>{
                    this.$emit('closeGoodsDetail');
                },300)
            },
            buyNow(itemId){
                let that = this;
                let tempObj = {
                    itemId:itemId,
                    number:1,
                    openAlert:true,
                    // belongSwiperIndex:that.goodsBox.belongSwiperIndex
                };
                this.$emit('buyNow',tempObj);
                this.closeSlideBottom();
            },
            addToCart(itemId){
                let that = this;
                let obj = {
                    itemId:itemId,
                    buyNum:1,
                    // belongSwiperIndex:that.goodsBox.belongSwiperIndex
                };
                this.$emit('addCart',obj);
                this.closeSlideBottom();
            },
        },
        components:{
            'slide-bottom':()=>import('../../../../components/commonComponents/slideBottom/SlideBottom'),
            'swiper':()=>import('../../../../components/commonComponents/swiperComponent/Swipers'),
            'goods-boxs':GoodsBox,
        },
        watch:{
            goodsDetailProps(val){
                this.goodsDetailMsg = Object.assign({},this.goodsDetailMsg,val);
            }
        }
    }
</script>

<style scoped lang="scss">
    .goods-detail{
        z-index: 1062;
    }
    .goods-detail-box{
        position: relative;
        padding: .15rem .15rem .65rem;
        overflow: auto;
        height: 5.5rem;
    }
    .goods-detail-price{
        color: #FF3333;
        font-size: .18rem;
        padding-bottom: .2rem;
    }
    .goods-detail-title{
        padding-right: .27rem;
        color: #333333;
        position: relative;
        font-size: .14rem;
        padding-bottom: .15rem;
    }
    .icon-close{
        position: absolute;
        right: .03rem;
        font-size: .11rem;
        color: #999999;
        top: .03rem;
        width: .24rem;
    }
    .goods-detail-des{
        color: #999999;
        padding-bottom: .15rem;
    }
    .goods-detail /deep/{
        .swiper-pagination-fraction{
            left: auto;
            bottom: auto;
            top: .15rem;
            right: .15rem;
            font-size: .11rem;
            width: auto;
            padding: .01rem .05rem;
            background-color: rgba(0,0,0,.2);
            border-radius: .25rem;
            color: #ffff;
        }
        #Swipers{
            padding-bottom: .1rem;
        }
        .booking-item-top-img{
            border-radius: .1rem;
        }
    }
    .buy-item-img{
        width: 100%;
        height: 100%;
        object-fit: cover;
        position: absolute;
        left: 0;
        top: 0;
    }
    .buy-item-wrap{
        display: inline-block;
        width: 1.7rem;
        height: 2.4rem;
        color: #fff;
        position: relative;
    }
    .buy-item-wuser{
        padding: .11rem;
        position: relative;
        z-index: 1;
        height: 100%;
        width: 100%;
        border-radius: .05rem;
        overflow: hidden;
        background-color: rgba(0,0,0,.2);
        font-size: .14rem;
        flex-direction: column-reverse;
    }
    .bus-show-title{
        height: .37rem;
        line-height: .37rem;
        width: 100%;
        color: #666;
        font-size: .13rem;
    }
    .buy-show{
        flex-wrap:wrap;
    }
    .buy-userheader{
        width: .24rem;
        height: .24rem;
        margin-right: .1rem;
    }
    .buy-user-msg{
        width: 100%;
    }
    .buy-show-more{
        width: 100%;
        font-size: .12rem;
        color: #666666;
        text-align: right;
        height: .4rem;
        line-height: .4rem;
    }

    .buy-btn{
        border-top-left-radius: .25rem;
        border-bottom-left-radius: .25rem;
        background-color:  #f3cb51;
        /*background-image: linear-gradient(to right,#FF7E7D,#FF3E3E);*/
    }
    .add-btn{
        border-top-right-radius: .25rem;
        border-bottom-right-radius: .25rem;
        background-color:  #ef6055;
        /*background-image: linear-gradient(to right,#9EBDFF,#5D89E8);*/
    }
    .detail-btn{
        height: .44rem;
        width: 1.48rem;
        text-align: center;
        line-height: .44rem;
        font-size: .16rem;
        color: #fff;
        /*-webkit-box-shadow: 0 0 .05rem 0 #999;*/
        /*-moz-box-shadow: 0 0 .05rem 0 #999;*/
        /*box-shadow: 0 0 .05rem 0 #999;*/
    }
    .detail-btns{
        z-index: 1;
        position: fixed;
        left: 0;
        right: 0;
        top: 90%;
        top: 6rem;
        top: 90vh;
        margin: auto;
        padding: 0 .15rem;
    }
    .right-slide-icon{
        position: absolute;
        right: .1rem;
        top: 1rem;
        z-index: 1;
        width: .32rem;
    }
    .service-wicon{
        width: .3rem;
        color: #fff;
        font-size: .12rem;
        position: fixed;
        right: .15rem;
        bottom: 10%;
        z-index: 10;
        .service-icon{
            width: 100%;
        }
        p{
            text-shadow: 0 0 .01rem #000;
            white-space: nowrap;
            position: relative;
            text-align: center;
        }
    }
    .cart-number{
        position: absolute;
        display: inline-block;
        color: #fff;
        border-radius: .25rem;
        padding: .02rem .02rem;
        background-color: #ef6055;
        left: .15rem;
        transform: scale(0.7);
        top: -.08rem;
        min-width: .15rem;
    }

</style>